Using OLR
vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
p <- plot(vclust)
par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil + TC_weath_rock + TC_unstable_structure + T_construction + spring + landfill + garbage + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
brick <- count(train.data$brick) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "brick")
wood <- count(train.data$wood) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wood")
mixed <- count(train.data$mixed) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "mixed")
TC_mature_soil <- count(train.data$TC_mature_soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_mature_soil")
T_construction <- count(train.data$T_construction ) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "T_construction ")
spring <- count(train.data$spring) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "spring")
landfill <- count(train.data$landfill) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "landfill")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
conc_rainfall <- count(train.data$conc_rainfall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_saprolite_soil <- count(train.data$TC_saprolite_soil ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_saprolite_soil ")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
TC_unstable_structure <- count(train.data$TC_unstable_structure ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_unstable_structure ")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
TC_weath_rock <- count(train.data$TC_weath_rock ) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_weath_rock ")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil, banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)
df
## x freq Percentage Classifier
## 1 FALSE 36 13.5849057 brick
## 2 TRUE 494 186.4150943 brick
## 3 FALSE 456 172.0754717 wood
## 4 TRUE 74 27.9245283 wood
## 5 FALSE 493 186.0377358 mixed
## 6 TRUE 37 13.9622642 mixed
## 7 FALSE 260 98.1132075 TC_mature_soil
## 8 TRUE 270 101.8867925 TC_mature_soil
## 9 FALSE 224 84.5283019 T_construction
## 10 TRUE 306 115.4716981 T_construction
## 11 FALSE 512 193.2075472 spring
## 12 TRUE 18 6.7924528 spring
## 13 FALSE 336 126.7924528 landfill
## 14 TRUE 194 73.2075472 landfill
## 15 FALSE 357 134.7169811 garbage
## 16 TRUE 173 65.2830189 garbage
## 17 FALSE 445 167.9245283 crack
## 18 TRUE 85 32.0754717 crack
## 19 FALSE 498 187.9245283 leaning_wall
## 20 TRUE 32 12.0754717 leaning_wall
## 21 FALSE 320 120.7547170 DepTaludeAterro
## 22 TRUE 210 79.2452830 DepTaludeAterro
## 23 FALSE 474 178.8679245 scars
## 24 TRUE 56 21.1320755 scars
## 25 FALSE 435 164.1509434 tilted
## 26 TRUE 95 35.8490566 tilted
## 27 FALSE 18 6.7924528 conc_rainfall
## 28 TRUE 512 193.2075472 conc_rainfall
## 29 FALSE 206 77.7358491 wastewater
## 30 TRUE 324 122.2641509 wastewater
## 31 FALSE 346 130.5660377 conc_rainfall_water
## 32 TRUE 184 69.4339623 conc_rainfall_water
## 33 FALSE 527 198.8679245 septic_tank
## 34 TRUE 3 1.1320755 septic_tank
## 35 C 28 26.4150943 angle
## 36 D 125 117.9245283 angle
## 37 E 377 355.6603774 angle
## 38 FALSE 349 131.6981132 EN
## 39 TRUE 181 68.3018868 EN
## 40 FALSE 26 9.8113208 TC
## 41 TRUE 504 190.1886792 TC
## 42 FALSE 445 167.9245283 TC_saprolite_soil
## 43 TRUE 85 32.0754717 TC_saprolite_soil
## 44 FALSE 361 136.2264151 banana
## 45 TRUE 169 63.7735849 banana
## 46 Y 70 39.6151669 drainage
## 47 P 241 136.3893605 drainage
## 48 N 219 123.9388795 drainage
## 49 FALSE 489 184.5283019 deforestation
## 50 TRUE 41 15.4716981 deforestation
## 51 FALSE 517 195.0943396 TC_unstable_structure
## 52 TRUE 13 4.9056604 TC_unstable_structure
## 53 FALSE 203 76.6037736 tree
## 54 TRUE 327 123.3962264 tree
## 55 FALSE 160 60.3773585 ground_veg
## 56 TRUE 370 139.6226415 ground_veg
## 57 d1 72 54.3396226 density
## 58 d2 421 317.7358491 density
## 59 d3 37 27.9245283 density
## 60 FALSE 518 195.4716981 TC_weath_rock
## 61 TRUE 12 4.5283019 TC_weath_rock
## 62 FALSE 529 199.6226415 fracture
## 63 TRUE 1 0.3773585 fracture
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk ~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -1.06800359 0.4434310 -2.40850014 8.009110e-03
## woodTRUE 1.26107034 0.3400823 3.70813294 1.043965e-04
## ENTRUE 0.57035097 0.3740951 1.52461471 6.367761e-02
## TC_mature_soilTRUE 0.54250106 0.2184423 2.48349789 6.504955e-03
## T_constructionTRUE 0.70778568 0.3648985 1.93967829 2.620940e-02
## springTRUE -0.96403829 0.6418554 -1.50195567 6.655428e-02
## landfillTRUE -0.17918500 0.3313524 -0.54076869 2.943335e-01
## leakTRUE -0.17063556 0.2360242 -0.72295782 2.348529e-01
## garbageTRUE -0.22130183 0.2977924 -0.74314129 2.286981e-01
## crackTRUE 1.97407258 0.3344921 5.90170203 1.798853e-09
## leaning_wallTRUE 2.00490794 0.5206348 3.85089128 5.884437e-05
## scarsTRUE 3.80117201 0.3435832 11.06332270 9.448250e-29
## downward_floorTRUE 1.28453811 0.3836629 3.34809052 4.068521e-04
## tiltedTRUE 1.05358907 0.3177892 3.31537042 4.576088e-04
## septic_tankTRUE 0.04304422 1.4490197 0.02970575 4.881509e-01
## conc_rainfallTRUE 1.87732511 0.5431539 3.45634125 2.737808e-04
## wastewaterTRUE 0.60520085 0.2331554 2.59569686 4.719965e-03
## ground_vegTRUE 0.71098812 0.2473930 2.87392118 2.027051e-03
## angleD 0.35595417 0.4883695 0.72886233 2.330429e-01
## angleE 0.18581360 0.5641278 0.32938214 3.709334e-01
## TC_saprolite_soilTRUE 0.04327260 0.2928845 0.14774632 4.412715e-01
## R1|R2 0.31194934 0.8956919 0.34827750 3.638159e-01
## R2|R3 4.54083034 0.9362909 4.84980732 6.179073e-07
## R3|R4 9.59071214 1.0254985 9.35224400 4.290377e-21
stargazer((ctable), type="text", style="default", digits = 2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -1.07 0.44 -2.41 0.01
## woodTRUE 1.26 0.34 3.71 0.0001
## ENTRUE 0.57 0.37 1.52 0.06
## TC_mature_soilTRUE 0.54 0.22 2.48 0.01
## T_constructionTRUE 0.71 0.36 1.94 0.03
## springTRUE -0.96 0.64 -1.50 0.07
## landfillTRUE -0.18 0.33 -0.54 0.29
## leakTRUE -0.17 0.24 -0.72 0.23
## garbageTRUE -0.22 0.30 -0.74 0.23
## crackTRUE 1.97 0.33 5.90 0
## leaning_wallTRUE 2.00 0.52 3.85 0.0001
## scarsTRUE 3.80 0.34 11.06 0
## downward_floorTRUE 1.28 0.38 3.35 0.0004
## tiltedTRUE 1.05 0.32 3.32 0.0005
## septic_tankTRUE 0.04 1.45 0.03 0.49
## conc_rainfallTRUE 1.88 0.54 3.46 0.0003
## wastewaterTRUE 0.61 0.23 2.60 0.005
## ground_vegTRUE 0.71 0.25 2.87 0.002
## angleD 0.36 0.49 0.73 0.23
## angleE 0.19 0.56 0.33 0.37
## TC_saprolite_soilTRUE 0.04 0.29 0.15 0.44
## R1| R2 0.31 0.90 0.35 0.36
## R2| R3 4.54 0.94 4.85 0.0000
## R3| R4 9.59 1.03 9.35 0
## ------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN + TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 36|Inf | 2.8332133| 1.609437912|-0.4519851|
## | |Yes|493|Inf | 2.2981307|-0.101506946|-2.0955154|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |348|Inf | 1.9070703|-0.443931389|-2.4756043|
## | |Yes|181|Inf | 4.4942386| 0.881738350|-1.2280704|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |260|Inf | 1.8941745|-0.185142433|-2.2407097|
## | |Yes|269|Inf | 2.9802281| 0.171422266|-1.6593349|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +-----------------+---+---+----+----------+------------+----------+
## |spring |No |511|Inf | 2.2897370|-0.035228692|-2.0171228|
## | |Yes| 18|Inf | Inf| 0.955511445|-0.2231436|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |335|Inf | 1.8632184|-0.493350993|-2.6075090|
## | |Yes|194|Inf | 4.5643482| 0.876929658|-1.1972838|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |345|Inf | 1.9760632|-0.297834444|-2.4266973|
## | |Yes|184|Inf | 3.5779479| 0.557481315|-1.2809338|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |357|Inf | 2.0421701|-0.299129458|-2.3529102|
## | |Yes|172|Inf | 3.3202283| 0.624154309|-1.2943569|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |473|Inf | 2.2042917|-0.225046501|-2.2524607|
## | |Yes| 56|Inf | Inf| 3.295836866|-0.3610133|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank |No |526|Inf | 2.3215530|-0.007604599|-1.9073615|
## | |Yes| 3|Inf | Inf| 0.693147181| -Inf|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 28|Inf | Inf| 0.000000000|-3.2958369|
## | |D |125|Inf | 3.7054088| 0.905117431|-1.1093076|
## | |E |376|Inf | 2.0209453|-0.289233663|-2.2454267|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2587825|-0.108213585|-2.0200181|
## | |Yes| 85|Inf | 2.7725887| 0.554996842|-1.4615178|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
data= train.data
, method = "logistic", Hess = TRUE)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.93805399 0.5306767 -1.76765616 3.855920e-02
## woodTRUE 1.13425624 0.3554699 3.19086394 7.092403e-04
## ENTRUE 0.47872035 0.3931647 1.21760766 1.116866e-01
## TC_mature_soilTRUE 0.48649743 0.2272782 2.14053737 1.615568e-02
## T_constructionTRUE 0.71920921 0.3722120 1.93225707 2.666389e-02
## landfillTRUE -0.24902235 0.3386661 -0.73530344 2.310774e-01
## leakTRUE -0.30305829 0.2409441 -1.25779483 1.042330e-01
## garbageTRUE -0.21516738 0.3014620 -0.71374626 2.376920e-01
## crackTRUE 2.01100798 0.3371095 5.96544490 1.219842e-09
## leaning_wallTRUE 2.03501252 0.5295070 3.84322135 6.071493e-05
## treeTRUE -0.16913426 0.2486148 -0.68030659 2.481552e-01
## downward_floorTRUE 1.15360836 0.3836200 3.00716419 1.318486e-03
## tiltedTRUE 0.96515938 0.3182641 3.03257396 1.212388e-03
## ground_vegTRUE 0.65899757 0.2690825 2.44905383 7.161602e-03
## scarsTRUE 3.76699390 0.3475902 10.83745672 1.143709e-27
## mixedTRUE 0.02471816 0.5172665 0.04778612 4.809433e-01
## conc_rainfallTRUE 1.45300464 0.5730475 2.53557459 5.613151e-03
## wastewaterTRUE 0.45039320 0.2401050 1.87581794 3.034014e-02
## angleD 0.18570674 0.4842897 0.38346208 3.506886e-01
## angleE 0.06641678 0.5620605 0.11816660 4.529678e-01
## bananaTRUE 0.36261636 0.2601767 1.39373101 8.169942e-02
## drainage.L 0.80107184 0.2779955 2.88159971 1.978310e-03
## drainage.Q -0.15990284 0.1863207 -0.85821279 1.953875e-01
## TC_saprolite_soilTRUE 0.02033632 0.2997866 0.06783600 4.729581e-01
## TCTRUE -0.19466922 0.5346406 -0.36411231 3.578871e-01
## deforestationTRUE 0.39194172 0.3899147 1.00519859 1.574006e-01
## R1|R2 -0.43529380 1.1292570 -0.38546920 3.499449e-01
## R2|R3 3.92596552 1.1491351 3.41645239 3.172138e-04
## R3|R4 8.97054482 1.2232004 7.33366754 1.119691e-13
stargazer((ctable), type="text", style="default", digits=2)
##
## ======================================================
## Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE -0.94 0.53 -1.77 0.04
## woodTRUE 1.13 0.36 3.19 0.001
## ENTRUE 0.48 0.39 1.22 0.11
## TC_mature_soilTRUE 0.49 0.23 2.14 0.02
## T_constructionTRUE 0.72 0.37 1.93 0.03
## landfillTRUE -0.25 0.34 -0.74 0.23
## leakTRUE -0.30 0.24 -1.26 0.10
## garbageTRUE -0.22 0.30 -0.71 0.24
## crackTRUE 2.01 0.34 5.97 0
## leaning_wallTRUE 2.04 0.53 3.84 0.0001
## treeTRUE -0.17 0.25 -0.68 0.25
## downward_floorTRUE 1.15 0.38 3.01 0.001
## tiltedTRUE 0.97 0.32 3.03 0.001
## ground_vegTRUE 0.66 0.27 2.45 0.01
## scarsTRUE 3.77 0.35 10.84 0
## mixedTRUE 0.02 0.52 0.05 0.48
## conc_rainfallTRUE 1.45 0.57 2.54 0.01
## wastewaterTRUE 0.45 0.24 1.88 0.03
## angleD 0.19 0.48 0.38 0.35
## angleE 0.07 0.56 0.12 0.45
## bananaTRUE 0.36 0.26 1.39 0.08
## drainage.L 0.80 0.28 2.88 0.002
## drainage.Q -0.16 0.19 -0.86 0.20
## TC_saprolite_soilTRUE 0.02 0.30 0.07 0.47
## TCTRUE -0.19 0.53 -0.36 0.36
## deforestationTRUE 0.39 0.39 1.01 0.16
## R1| R2 -0.44 1.13 -0.39 0.35
## R2| R3 3.93 1.15 3.42 0.0003
## R3| R4 8.97 1.22 7.33 0
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+ TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +-----------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-----------------+---+---+----+----------+------------+----------+
## |brick |No | 36|Inf | 2.8332133| 1.609437912|-0.4519851|
## | |Yes|493|Inf | 2.2981307|-0.101506946|-2.0955154|
## +-----------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +-----------------+---+---+----+----------+------------+----------+
## |EN |No |348|Inf | 1.9070703|-0.443931389|-2.4756043|
## | |Yes|181|Inf | 4.4942386| 0.881738350|-1.2280704|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil |No |260|Inf | 1.8941745|-0.185142433|-2.2407097|
## | |Yes|269|Inf | 2.9802281| 0.171422266|-1.6593349|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction |No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill |No |335|Inf | 1.8632184|-0.493350993|-2.6075090|
## | |Yes|194|Inf | 4.5643482| 0.876929658|-1.1972838|
## +-----------------+---+---+----+----------+------------+----------+
## |leak |No |345|Inf | 1.9760632|-0.297834444|-2.4266973|
## | |Yes|184|Inf | 3.5779479| 0.557481315|-1.2809338|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage |No |357|Inf | 2.0421701|-0.299129458|-2.3529102|
## | |Yes|172|Inf | 3.3202283| 0.624154309|-1.2943569|
## +-----------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +-----------------+---+---+----+----------+------------+----------+
## |tree |No |202|Inf | 1.7076764|-0.547965171|-2.2650472|
## | |Yes|327|Inf | 2.9672042| 0.327043146|-1.7358008|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor |No |473|Inf | 2.2042917|-0.225046501|-2.2524607|
## | |Yes| 56|Inf | Inf| 3.295836866|-0.3610133|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +-----------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed |No |492|Inf | 2.2958961|-0.065063593|-1.9740810|
## | |Yes| 37|Inf | 2.8622009| 0.860201265|-1.2878543|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +-----------------+---+---+----+----------+------------+----------+
## |angle |C | 28|Inf | Inf| 0.000000000|-3.2958369|
## | |D |125|Inf | 3.7054088| 0.905117431|-1.1093076|
## | |E |376|Inf | 2.0209453|-0.289233663|-2.2454267|
## +-----------------+---+---+----+----------+------------+----------+
## |banana |No |360|Inf | 1.9459101|-0.359374001|-2.1972246|
## | |Yes|169|Inf | 4.4248466| 0.783298278|-1.4542450|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.7801586|-1.575536361|-3.5263605|
## | |P |240|Inf | 2.4537237|-0.546543706|-2.3978953|
## | |N |219|Inf | 3.5695327| 1.092533243|-1.3246502|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2587825|-0.108213585|-2.0200181|
## | |Yes| 85|Inf | 2.7725887| 0.554996842|-1.4615178|
## +-----------------+---+---+----+----------+------------+----------+
## |TC |No | 26|Inf | Inf| 0.810930216|-1.2039728|
## | |Yes|503|Inf | 2.2723452|-0.043744549|-1.9619105|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation |No |488|Inf | 2.3368742| 0.049190244|-1.8729849|
## | |Yes| 41|Inf | 2.2246236|-0.656779536|-2.5389739|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## woodTRUE 1.16443202 0.3344192 3.4819534 2.488852e-04
## TC_mature_soilTRUE 0.48039422 0.2161040 2.2229774 1.310866e-02
## T_constructionTRUE 0.48516262 0.2932156 1.6546277 4.900002e-02
## landfillTRUE -0.02320693 0.2972534 -0.0780712 4.688857e-01
## crackTRUE 1.98729825 0.3268080 6.0809351 5.974183e-10
## leaning_wallTRUE 2.07965826 0.5270628 3.9457507 3.977517e-05
## treeTRUE -0.11878902 0.2387166 -0.4976152 3.093777e-01
## downward_floorTRUE 1.08473106 0.3681854 2.9461541 1.608760e-03
## tiltedTRUE 1.00420680 0.3130299 3.2080223 6.682557e-04
## ground_vegTRUE 0.68821424 0.2615814 2.6309755 4.257008e-03
## scarsTRUE 3.68891379 0.3410446 10.8165134 1.437538e-27
## conc_rainfallTRUE 1.49896469 0.5672627 2.6424526 4.115399e-03
## wastewaterTRUE 0.43939795 0.2328797 1.8868019 2.959349e-02
## bananaTRUE 0.41640892 0.2496973 1.6676549 4.769213e-02
## drainage.L 0.79948756 0.2719775 2.9395356 1.643523e-03
## drainage.Q -0.11590723 0.1839551 -0.6300843 2.643197e-01
## R1|R2 0.63406774 0.5577303 1.1368717 1.277960e-01
## R2|R3 4.89779715 0.6155953 7.9561959 8.870470e-16
## R3|R4 9.83361613 0.7514390 13.0863789 1.969728e-39
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.16 0.33 3.48 0.0002
## TC_mature_soilTRUE 0.48 0.22 2.22 0.01
## T_constructionTRUE 0.49 0.29 1.65 0.05
## landfillTRUE -0.02 0.30 -0.08 0.47
## crackTRUE 1.99 0.33 6.08 0
## leaning_wallTRUE 2.08 0.53 3.95 0.0000
## treeTRUE -0.12 0.24 -0.50 0.31
## downward_floorTRUE 1.08 0.37 2.95 0.002
## tiltedTRUE 1.00 0.31 3.21 0.001
## ground_vegTRUE 0.69 0.26 2.63 0.004
## scarsTRUE 3.69 0.34 10.82 0
## conc_rainfallTRUE 1.50 0.57 2.64 0.004
## wastewaterTRUE 0.44 0.23 1.89 0.03
## bananaTRUE 0.42 0.25 1.67 0.05
## drainage.L 0.80 0.27 2.94 0.002
## drainage.Q -0.12 0.18 -0.63 0.26
## R1| R2 0.63 0.56 1.14 0.13
## R2| R3 4.90 0.62 7.96 0
## R3| R4 9.83 0.75 13.09 0
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |260|Inf | 1.8941745|-0.185142433|-2.2407097|
## | |Yes|269|Inf | 2.9802281| 0.171422266|-1.6593349|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |335|Inf | 1.8632184|-0.493350993|-2.6075090|
## | |Yes|194|Inf | 4.5643482| 0.876929658|-1.1972838|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |202|Inf | 1.7076764|-0.547965171|-2.2650472|
## | |Yes|327|Inf | 2.9672042| 0.327043146|-1.7358008|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |473|Inf | 2.2042917|-0.225046501|-2.2524607|
## | |Yes| 56|Inf | Inf| 3.295836866|-0.3610133|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |360|Inf | 1.9459101|-0.359374001|-2.1972246|
## | |Yes|169|Inf | 4.4248466| 0.783298278|-1.4542450|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.7801586|-1.575536361|-3.5263605|
## | |P |240|Inf | 2.4537237|-0.546543706|-2.3978953|
## | |N |219|Inf | 3.5695327| 1.092533243|-1.3246502|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## woodTRUE 1.1644451 0.3344545 3.4816251 2.488852e-04
## TC_mature_soilTRUE 0.4820550 0.2150829 2.2412525 1.310866e-02
## T_constructionTRUE 0.4713918 0.2343514 2.0114746 4.900002e-02
## crackTRUE 1.9838718 0.3238415 6.1260585 4.688857e-01
## leaning_wallTRUE 2.0811566 0.5265700 3.9522888 5.974183e-10
## treeTRUE -0.1165493 0.2369379 -0.4918982 3.977517e-05
## downward_floorTRUE 1.0817894 0.3662799 2.9534501 3.093777e-01
## tiltedTRUE 0.9989767 0.3058044 3.2667183 1.608760e-03
## ground_vegTRUE 0.6860575 0.2600567 2.6381069 6.682557e-04
## scarsTRUE 3.6891713 0.3409953 10.8188338 4.257008e-03
## conc_rainfallTRUE 1.4989010 0.5671314 2.6429519 1.437538e-27
## wastewaterTRUE 0.4424641 0.2295765 1.9273062 4.115399e-03
## bananaTRUE 0.4162586 0.2496792 1.6671735 2.959349e-02
## drainage.L 0.7987598 0.2718212 2.9385486 4.769213e-02
## drainage.Q -0.1157995 0.1839428 -0.6295407 1.643523e-03
## R1|R2 0.6353627 0.5572983 1.1400764 2.643197e-01
## R2|R3 4.8989925 0.6152733 7.9623036 1.277960e-01
## R3|R4 9.8351326 0.7510472 13.0952255 8.870470e-16
stargazer((ctable), type="text", style="default", digits=2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE 1.16 0.33 3.48 0.0002
## TC_mature_soilTRUE 0.48 0.22 2.24 0.01
## T_constructionTRUE 0.47 0.23 2.01 0.05
## crackTRUE 1.98 0.32 6.13 0.47
## leaning_wallTRUE 2.08 0.53 3.95 0
## treeTRUE -0.12 0.24 -0.49 0.0000
## downward_floorTRUE 1.08 0.37 2.95 0.31
## tiltedTRUE 1.00 0.31 3.27 0.002
## ground_vegTRUE 0.69 0.26 2.64 0.001
## scarsTRUE 3.69 0.34 10.82 0.004
## conc_rainfallTRUE 1.50 0.57 2.64 0
## wastewaterTRUE 0.44 0.23 1.93 0.004
## bananaTRUE 0.42 0.25 1.67 0.03
## drainage.L 0.80 0.27 2.94 0.05
## drainage.Q -0.12 0.18 -0.63 0.002
## R1| R2 0.64 0.56 1.14 0.26
## R2| R3 4.90 0.62 7.96 0.13
## R3| R4 9.84 0.75 13.10 0
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |260|Inf | 1.8941745|-0.185142433|-2.2407097|
## | |Yes|269|Inf | 2.9802281| 0.171422266|-1.6593349|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |202|Inf | 1.7076764|-0.547965171|-2.2650472|
## | |Yes|327|Inf | 2.9672042| 0.327043146|-1.7358008|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |473|Inf | 2.2042917|-0.225046501|-2.2524607|
## | |Yes| 56|Inf | Inf| 3.295836866|-0.3610133|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |360|Inf | 1.9459101|-0.359374001|-2.1972246|
## | |Yes|169|Inf | 4.4248466| 0.783298278|-1.4542450|
## +--------------+---+---+----+----------+------------+----------+
## |drainage |Y | 70|Inf | 0.7801586|-1.575536361|-3.5263605|
## | |P |240|Inf | 2.4537237|-0.546543706|-2.3978953|
## | |N |219|Inf | 3.5695327| 1.092533243|-1.3246502|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -0.9154798 0.4407467 -2.0771112 1.889565e-02
## woodTRUE 1.2187649 0.3324982 3.6654787 1.234382e-04
## TC_mature_soilTRUE 0.4761820 0.2140928 2.2241851 1.306800e-02
## T_constructionTRUE 0.5470797 0.2300691 2.3778927 8.705947e-03
## crackTRUE 1.9307592 0.3201583 6.0306395 8.165607e-10
## leaning_wallTRUE 1.8500694 0.5235969 3.5333847 2.051375e-04
## scarsTRUE 3.7625502 0.3395457 11.0811308 7.745184e-29
## downward_floorTRUE 1.1884288 0.3690203 3.2204975 6.398415e-04
## tiltedTRUE 1.1103260 0.3068371 3.6186172 1.480907e-04
## conc_rainfallTRUE 1.9000278 0.5367538 3.5398494 2.001777e-04
## wastewaterTRUE 0.5432397 0.2235931 2.4295902 7.557952e-03
## ground_vegTRUE 0.8479276 0.2345053 3.6158137 1.497028e-04
## R1|R2 0.2825837 0.6838108 0.4132483 3.397123e-01
## R2|R3 4.4183960 0.7364967 5.9992066 9.914200e-10
## R3|R4 9.3567928 0.8350943 11.2044752 1.938222e-29
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -0.92 0.44 -2.08 0.02
## woodTRUE 1.22 0.33 3.67 0.0001
## TC_mature_soilTRUE 0.48 0.21 2.22 0.01
## T_constructionTRUE 0.55 0.23 2.38 0.01
## crackTRUE 1.93 0.32 6.03 0
## leaning_wallTRUE 1.85 0.52 3.53 0.0002
## scarsTRUE 3.76 0.34 11.08 0
## downward_floorTRUE 1.19 0.37 3.22 0.001
## tiltedTRUE 1.11 0.31 3.62 0.0001
## conc_rainfallTRUE 1.90 0.54 3.54 0.0002
## wastewaterTRUE 0.54 0.22 2.43 0.01
## ground_vegTRUE 0.85 0.23 3.62 0.0001
## R1| R2 0.28 0.68 0.41 0.34
## R2| R3 4.42 0.74 6.00 0
## R3| R4 9.36 0.84 11.20 0
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 36|Inf | 2.8332133| 1.609437912|-0.4519851|
## | |Yes|493|Inf | 2.2981307|-0.101506946|-2.0955154|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |260|Inf | 1.8941745|-0.185142433|-2.2407097|
## | |Yes|269|Inf | 2.9802281| 0.171422266|-1.6593349|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |473|Inf | 2.2042917|-0.225046501|-2.2524607|
## | |Yes| 56|Inf | Inf| 3.295836866|-0.3610133|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## brickTRUE -1.12193398 0.5161824 -2.1735222 1.487052e-02
## woodTRUE 1.07366206 0.3356084 3.1991514 6.891638e-04
## mixedTRUE 0.33992301 0.4973194 0.6835104 2.471422e-01
## ENTRUE 0.49216761 0.3838805 1.2820855 9.990632e-02
## TCTRUE 0.18875929 0.5051849 0.3736440 3.543346e-01
## T_constructionTRUE 0.58652586 0.3569660 1.6430861 5.018256e-02
## landfillTRUE -0.06970011 0.3262988 -0.2136082 4.154263e-01
## leakTRUE -0.08885997 0.2305788 -0.3853778 3.499787e-01
## garbageTRUE -0.08288739 0.2925339 -0.2833429 3.884570e-01
## crackTRUE 1.90086296 0.3284512 5.7873536 3.575199e-09
## leaning_wallTRUE 2.04340641 0.5273765 3.8746635 5.338607e-05
## treeTRUE -0.17275809 0.2419904 -0.7139046 2.376431e-01
## tiltedTRUE 1.09092737 0.3107130 3.5110450 2.231744e-04
## angleD 0.22193237 0.4743440 0.4678722 3.199380e-01
## angleE 0.10377558 0.5489883 0.1890306 4.250344e-01
## ground_vegTRUE 0.71814526 0.2606371 2.7553452 2.931512e-03
## scarsTRUE 3.87149244 0.3454210 11.2080408 1.861720e-29
## conc_rainfallTRUE 2.03442386 0.5391154 3.7736333 8.044360e-05
## wastewaterTRUE 0.55271565 0.2300166 2.4029384 8.131963e-03
## bananaTRUE 0.51404490 0.2537603 2.0257103 2.139724e-02
## R1|R2 0.28510663 1.0709128 0.2662277 3.950319e-01
## R2|R3 4.41925742 1.1004173 4.0159833 2.959922e-05
## R3|R4 9.37573715 1.1775912 7.9617931 8.478190e-16
stargazer((ctable), type="text", style="default", digits = 2)
##
## ===================================================
## Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE -1.12 0.52 -2.17 0.01
## woodTRUE 1.07 0.34 3.20 0.001
## mixedTRUE 0.34 0.50 0.68 0.25
## ENTRUE 0.49 0.38 1.28 0.10
## TCTRUE 0.19 0.51 0.37 0.35
## T_constructionTRUE 0.59 0.36 1.64 0.05
## landfillTRUE -0.07 0.33 -0.21 0.42
## leakTRUE -0.09 0.23 -0.39 0.35
## garbageTRUE -0.08 0.29 -0.28 0.39
## crackTRUE 1.90 0.33 5.79 0
## leaning_wallTRUE 2.04 0.53 3.87 0.0001
## treeTRUE -0.17 0.24 -0.71 0.24
## tiltedTRUE 1.09 0.31 3.51 0.0002
## angleD 0.22 0.47 0.47 0.32
## angleE 0.10 0.55 0.19 0.43
## ground_vegTRUE 0.72 0.26 2.76 0.003
## scarsTRUE 3.87 0.35 11.21 0
## conc_rainfallTRUE 2.03 0.54 3.77 0.0001
## wastewaterTRUE 0.55 0.23 2.40 0.01
## bananaTRUE 0.51 0.25 2.03 0.02
## R1| R2 0.29 1.07 0.27 0.40
## R2| R3 4.42 1.10 4.02 0.0000
## R3| R4 9.38 1.18 7.96 0
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk) N= 529 , 1 Missing
##
## +--------------+---+---+----+----------+------------+----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------+---+---+----+----------+------------+----------+
## |brick |No | 36|Inf | 2.8332133| 1.609437912|-0.4519851|
## | |Yes|493|Inf | 2.2981307|-0.101506946|-2.0955154|
## +--------------+---+---+----+----------+------------+----------+
## |wood |No |455|Inf | 2.2094947|-0.198450939|-2.2598232|
## | |Yes| 74|Inf | 3.5835189| 1.369487243|-0.6729445|
## +--------------+---+---+----+----------+------------+----------+
## |mixed |No |492|Inf | 2.2958961|-0.065063593|-1.9740810|
## | |Yes| 37|Inf | 2.8622009| 0.860201265|-1.2878543|
## +--------------+---+---+----+----------+------------+----------+
## |EN |No |348|Inf | 1.9070703|-0.443931389|-2.4756043|
## | |Yes|181|Inf | 4.4942386| 0.881738350|-1.2280704|
## +--------------+---+---+----+----------+------------+----------+
## |TC |No | 26|Inf | Inf| 0.810930216|-1.2039728|
## | |Yes|503|Inf | 2.2723452|-0.043744549|-1.9619105|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |224|Inf | 1.5567942|-0.894516932|-3.1734135|
## | |Yes|305|Inf | 3.6142906| 0.629865731|-1.4277941|
## +--------------+---+---+----+----------+------------+----------+
## |landfill |No |335|Inf | 1.8632184|-0.493350993|-2.6075090|
## | |Yes|194|Inf | 4.5643482| 0.876929658|-1.1972838|
## +--------------+---+---+----+----------+------------+----------+
## |leak |No |345|Inf | 1.9760632|-0.297834444|-2.4266973|
## | |Yes|184|Inf | 3.5779479| 0.557481315|-1.2809338|
## +--------------+---+---+----+----------+------------+----------+
## |garbage |No |357|Inf | 2.0421701|-0.299129458|-2.3529102|
## | |Yes|172|Inf | 3.3202283| 0.624154309|-1.2943569|
## +--------------+---+---+----+----------+------------+----------+
## |crack |No |444|Inf | 2.1822989|-0.317967468|-2.6246686|
## | |Yes| 85|Inf | 3.7256934| 2.264363880|-0.2125614|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall |No |497|Inf | 2.2591000|-0.132992454|-2.1905356|
## | |Yes| 32|Inf | Inf| Inf| 0.2513144|
## +--------------+---+---+----+----------+------------+----------+
## |tree |No |202|Inf | 1.7076764|-0.547965171|-2.2650472|
## | |Yes|327|Inf | 2.9672042| 0.327043146|-1.7358008|
## +--------------+---+---+----+----------+------------+----------+
## |tilted |No |434|Inf | 2.1082771|-0.392042088|-2.4336134|
## | |Yes| 95|Inf | Inf| 2.696876901|-0.6306268|
## +--------------+---+---+----+----------+------------+----------+
## |angle |C | 28|Inf | Inf| 0.000000000|-3.2958369|
## | |D |125|Inf | 3.7054088| 0.905117431|-1.1093076|
## | |E |376|Inf | 2.0209453|-0.289233663|-2.2454267|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg |No |160|Inf | 1.3862944|-1.132228899|-2.5123056|
## | |Yes|369|Inf | 3.1612467| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars |No |319|Inf | 1.7808304|-1.421941700|-4.1399551|
## | |Yes|210|Inf | 5.3423343| 3.228826156|-0.8472979|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 18|Inf |-0.4519851|-2.833213344| -Inf|
## | |Yes|511|Inf | 2.5797959| 0.058725286|-1.8740621|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater |No |206|Inf | 1.6211340|-0.474739234|-2.6977408|
## | |Yes|323|Inf | 3.1716229| 0.293102140|-1.5836538|
## +--------------+---+---+----+----------+------------+----------+
## |banana |No |360|Inf | 1.9459101|-0.359374001|-2.1972246|
## | |Yes|169|Inf | 4.4248466| 0.783298278|-1.4542450|
## +--------------+---+---+----+----------+------------+----------+
## |Overall | |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 3 15 1 0
## R2 3 82 8 0
## R3 0 17 56 11
## R4 0 0 13 15
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.3035714
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 3 15 1 0
## R2 2 83 8 0
## R3 0 16 56 12
## R4 0 0 12 16
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.2946429
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 3 15 1 0
## R2 2 83 8 0
## R3 0 18 57 9
## R4 0 0 10 18
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.28125
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 3 15 1 0
## R2 2 83 8 0
## R3 0 18 57 9
## R4 0 0 10 18
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.28125
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 3 15 1 0
## R2 3 82 8 0
## R3 0 18 57 9
## R4 0 0 13 15
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2991071
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 2 16 1 0
## R2 2 83 8 0
## R3 0 20 56 8
## R4 0 0 12 16
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.2991071
#Table
df2 <- data.frame(
"Equations"=c(1:6),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6
)
)
df2
## Equations Predicted
## 1 1 0.6964286
## 2 2 0.7053571
## 3 3 0.7187500
## 4 4 0.7187500
## 5 5 0.7008929
## 6 6 0.7008929